const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    permisson_des : "",
    leve_1: "",
    leve_2: "",
    admin: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.showPermisson()
  },

  showPermisson : function() {
    if (app.globalData.userInfo.current_permission == 3) {
      this.setData({
        permisson_des : "管理员权限"
      })
    } else if (app.globalData.userInfo.current_permission == 2) {
      this.setData({
        permisson_des : "二级权限"
      })
    } else if (app.globalData.userInfo.current_permission == 1) {
      this.setData({
        permisson_des : "一级权限"
      })
    } else {
      this.setData({
        permisson_des : "无"
      })
    }
  },

  changeContent1 : function(e) {
    const value =  e.detail.value;
    this.data.leve_1 = value
  },

  handleValidate1 : function(e) {
    if (this.data.leve_1 == app.globalData.permission.level_1) {
      wx.showModal({
        content: '一级权限验证成功',
      })

      app.globalData.userInfo.current_permission = 1
      wx.setStorageSync('userinfo', app.globalData.userInfo)
      this.showPermisson()
    } else {
      wx.showModal({
        content: '一级权限验证失败',
      })
    }
  },

  changeContent2 : function(e) {
    const value =  e.detail.value;
    this.data.leve_2 = value
  },

  handleValidate2 : function(e) {
    if (this.data.leve_2 == app.globalData.permission.level_2) {
      wx.showModal({
        content: '二级权限验证成功',
      })
      app.globalData.userInfo.current_permission = 2
      wx.setStorageSync('userinfo', app.globalData.userInfo)
      this.showPermisson()
    } else {
      wx.showModal({
        content: '二级权限验证失败',
      })
    }
  },

  changeContentAdmin : function(e) {
    const value =  e.detail.value;
    this.data.admin = value
  },

  handleValidateAdmin : function(e) {
    if (this.data.admin == app.globalData.permission.admin) {
      wx.showModal({
        content: '管理员权限验证成功',
      })
      app.globalData.userInfo.current_permission = 3
      wx.setStorageSync('userinfo', app.globalData.userInfo)
      this.showPermisson()
    } else {
      wx.showModal({
        content: '管理员权限验证失败',
      })
    }
  },
})